package wsn.networklayer;

// //
// @Author Hien Hoang
// @Version Nov 26, 2013
// //

import inet.networklayer.arp.ARP;
import wsn.networklayer.ipv4.WSNIPv4;
import inet.networklayer.autorouting.ipv4.IPv4NodeConfigurator;
import wsn.networklayer.lbtr.LBTR;

module WSNNetworkLayer {
    
    parameters:
        @display("i=block/fork");
        bool isBaseStation = default(false);
    gates:
        input dataAppIn;
        output dataAppOut;
        input ifIn[];
        output ifOut[];
    submodules:
        configurator: IPv4NodeConfigurator {
            @display("p=39,158");
        }
        
        ip: WSNIPv4 {
            parameters:
                protocolMapping = "2000:0, 1000:1";
                @display("p=85,95;q=queue");
            gates:
                protocolIn[2];
                protocolOut[2];
                queueIn[sizeof(ifIn)];        
        }
        
        routing: LBTR{
         	parameters:
         	    @display("p=202,95");
         	    isBaseStation = isBaseStation;   
        }
        
        arp: ARP {
            parameters:
                @display("p=202,200;q=pendingQueue");
            gates:
                nicOut[sizeof(ifOut)];
        }
        
	connections allowunconnected:
	    ip.protocolOut[0] --> { @display("m=n"); } --> dataAppOut;
	    ip.protocolIn[0] <-- { @display("m=n"); } <-- dataAppIn;
	    
	    ip.protocolOut[1] --> routing.ipIn;
	    ip.protocolIn[1] <-- routing.ipOut;
	    
	    ip.queueOut --> arp.ipIn;
	    
	    for i=0..sizeof(ifIn)-1 {
            ifIn[i] --> { @display("m=s"); } --> ip.queueIn[i];
        }
        for i=0..sizeof(ifOut)-1 {
            arp.nicOut[i] --> { @display("m=s"); } --> ifOut[i];
        }
    
}
